package com.medical.data.controller;


import com.medical.data.component.TemplateTypeComponent;
import com.medical.data.domain.FormTemplateType;
import com.medical.data.service.FormTemplateTypeService;
import com.medical.data.utils.Result;
import com.medical.data.vo.AddTemplateTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cj
 * @since 2024-02-14
 */
@RestController
@RequestMapping("/data/form-template-type")
@Api(description = "表单类型管理")
@Slf4j
public class FormTemplateTypeController {

    @Autowired
    private FormTemplateTypeService formTemplateTypeService;

    @Autowired
    private TemplateTypeComponent templateTypeComponent;

    @ApiOperation("获取全部类型的表单")
    @PostMapping("/getAllFormTemType")
    public Result getAllFormTemType() {
        log.info("/data/form-template-type/getAllFormTemType参数========>{}", "无");
        Map<String, FormTemplateType> stringFormTemplateTypeMap = templateTypeComponent.get();
        return Result.ok().data("formTemplateTypes", stringFormTemplateTypeMap);
    }


    @ApiOperation("新增表单类型")
    @PostMapping("/addTemplateType")
    public Result addTemplateType(@Validated @RequestBody AddTemplateTypeVo addTemplateTypeVo) {
        log.info("/data/form-template-type/addTemplateType参数========>{}", addTemplateTypeVo);
        formTemplateTypeService.addTemplateType(addTemplateTypeVo);
        return Result.ok();
    }

}

